package ude.univ.esiag.gon.uchiha.topic;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.StringTokenizer;

import ude.univ.esiag.gon.uchiha.data.DataObject;

public class SerializableTopic implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private ArrayList<SerializableTopic> topics;
	private String name;
	private String simpleName;
	private DataObject data;
	public SerializableTopic(String simpleName, String name, DataObject data){
		this.simpleName = simpleName;
		this.name = name;
		this.data = data;
		this.topics = new ArrayList<SerializableTopic>();
	}
	public SerializableTopic get(int index){
		return topics.get(index);
	}
	public int size(){
		return topics.size();
	}
	public void addTopic(SerializableTopic topic){
		topics.add(topic);
	}
	public ArrayList<SerializableTopic> getTopics() {
		return topics;
	}
	public void setTopics(ArrayList<SerializableTopic> topics) {
		this.topics = topics;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getSimpleName() {
		return simpleName;
	}
	public void setSimpleName(String simpleName) {
		this.simpleName = simpleName;
	}
	public DataObject getData() {
		return data;
	}
	public void setData(DataObject data) {
		this.data = data;
	}
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i<getLevel();i++){
			sb.append("-");
		}
		if(data.getObj() != null){
			sb.append(simpleName + "[" + data.getObj().getClass().getSimpleName() + "]\n");
		}else{
			sb.append(simpleName + "[null]\n");
		}
		for(int i = 0;i<topics.size();i++){
			sb.append(topics.get(i).toString());
		}
		return sb.toString();
	}
	public int getLevel(){
		StringTokenizer tockens = new StringTokenizer(name, ".");
		return tockens.countTokens();
	}
}
